# Maintainer: Some One <some.one@some.email.com>

_realname=vid.stab
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1
pkgrel=1
pkgdesc="Video stabilization library (mingw-w64)"
arch=('any')
url='http://public.hronopik.de/vid.stab'
license=('GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "git")
options=('strip' 'staticlibs')
_hash='2d82492533bf5004bc2c4f8213a1b622c45f6a44'
source=(""vid.stab-${pkgver}::git+https://github.com/georgmartius/vid.stab.git#commit=${_hash}"")
sha256sums=('SKIP')

prepare() {
  cd "$srcdir"/${_realname}-${pkgver}
 
  if [[ -d build ]]; then
    rm -rf build
  fi
  mkdir build
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH}-static ]] && rm -rf "${srcdir}"/build-${CARCH}-static
  mkdir -p "${srcdir}"/build-${CARCH}-static && cd "${srcdir}"/build-${CARCH}-static

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      ../${_realname}-${pkgver}

  make
  [[ -d "${srcdir}"/build-${CARCH}-shared ]] && rm -rf "${srcdir}"/build-${CARCH}-shared
  mkdir -p "${srcdir}"/build-${CARCH}-shared && cd "${srcdir}"/build-${CARCH}-shared

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -G'MSYS Makefiles' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=OFF \
      ../${_realname}-${pkgver}

  make
}

#check() {
#  cd "${srcdir}"/build-${CARCH}
#  make check
#}

package() {
  cd "${srcdir}"/build-${CARCH}-static
  make install DESTDIR="${pkgdir}"
  cd "${srcdir}"/build-${CARCH}-shared
  make install DESTDIR="${pkgdir}"
}
